﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Portal.Exam.Model;
using Portal.Web.Model;
using Portal.Exam.Bussiness;
using Portal.Web.Utility;
using Portal.Core;
using Portal.Systems.Model;

namespace Portal.Exam.Render
{
    public class GroupQuestionRenderBll
    {
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut Draw(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                //GroupQuestionCls[] GroupQuestions = GroupQuestionBll.ReadingGroupQuestion(SiteId, null);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                bool CheckAllowManage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, ExamPermission.StaticId, ExamPermission.funcQuestionManage, ExamPermission.StaticId, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                string Html =
                #region Javascript
 " <script language=javascript>\r\n" +
                   "    function ClientReading()\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        UserType = document.getElementById('txtSelectedUserType').value;\r\n" +
                   "        AjaxOut = Portal.Exam.Render.GroupQuestionRenderBll.ServerSideReading(SiteId, UserType).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +

                   "        document.getElementById('divListItemContent').innerHTML = AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                   "    function ClientAdd()\r\n" +
                   "    {\r\n" +
                   "         SelectedNode = $(\"#tree\").dynatree(\"getActiveNode\");\r\n" +
                   "         if(SelectedNode==null)\r\n" +
                   "         {\r\n" +
                   "            alert('Chưa xác định vào nhóm cần thêm!');\r\n" +
                   "            return;\r\n" +
                   "         }\r\n" +

                   "        AccountType = SelectedNode.data.href;\r\n" +
                   "        if(AccountType=='root')\r\n" +
                   "        {\r\n" +
                   "            alert('Chưa xác định vào nhóm cần thêm! Không thể thêm vào nhóm gốc!');\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        window.open('AddGroupQuestion.aspx?AccountType='+AccountType,'_self');\r\n" +
                   "    }\r\n" +

                   "    function ClientUpdate(GroupQuestionId)\r\n" +
                   "    {\r\n" +
                   "        window.open('UpdateGroupQuestion.aspx?GroupQuestionId='+GroupQuestionId,'_self');\r\n" +
                   "    }\r\n" +

                   "    function ClientDelete(Id)\r\n" +
                   "    {\r\n" +
                   "        SiteId='" + SiteId + "';\r\n" +
                   "        if(confirm('Bạn đã chắc chắn xóa chưa?')==false)return;\r\n" +
                   "        UserType = document.getElementById('txtSelectedUserType').value;\r\n" +
                   "        AjaxOut = Portal.Exam.Render.GroupQuestionRenderBll.ServerSideDeleteGroupQuestion(SiteId,Id,UserType).value;\r\n" +
                   "        if(AjaxOut.Error)\r\n" +
                   "        {\r\n" +
                   "            alert(AjaxOut.InfoMessage);\r\n" +
                   "            return;\r\n" +
                   "        }\r\n" +
                   "        document.getElementById('divListItemContent').innerHTML=AjaxOut.HtmlContent;\r\n" +
                   "    }\r\n" +

                   "    function ClientLoadRecord(Id)\r\n" +
                   "    {\r\n" +
                   "        document.getElementById('txtSelectedUserType').value=Id;\r\n" +
                   "        ClientReading();\r\n" +
                   "    }\r\n" +

                   " </script>\r\n" +

                #endregion

                " <input id=\"txtSelectedUserType\" type=\"hidden\">\r\n" +
                   " <div class=FormFunction id=divListForm>\r\n" +
                   "    <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n";
                if (CheckAllowManage)
                {
                    Html +=
                   "            <li onclick=\"javascript:ClientAdd();\"><img class=image src=\"" + IconRoot + "/Add.png\"><div>Tạo mới</div></li>\r\n";
                }
                Html +=
                   "            <li onclick=\"javascript:window.open('../../folder.aspx?folder=exam','_self');\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "    </div>\r\n" +
                   "    <div id=\"divListItems\">\r\n" +
                   "        <table>\r\n" +
                   "        <tr>\r\n" +
                   "            <td class=col1>\r\n" +
                   "                <div class=CssTreeView>\r\n" +
                                        ExamUltility.DrawTreeViewByAccountType(SiteId,WebSessionUtility.GetCurrentLoginUser().UserId).HtmlContent +
                   "                </div>\r\n" +
                   "            </td>\r\n" +
                   "            <td class=col2>\r\n" +
                   "                <div id=divListItemContent>\r\n" +
                                        ServerSideReading(SiteId, "").HtmlContent +
                   "                </div>\r\n" +
                   "            </td>\r\n" +
                   "        </tr>\r\n" +
                   "        </table>\r\n" +
                   "    </div>\r\n" +
                   "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }
        
        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideReading(string SiteId, string UserType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {

                //bool CheckAllowManage = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, ExamPermission.StaticId, ExamPermission.funcQuestionManage, ExamPermission.StaticId, WebSessionUtility.GetCurrentLoginUser().UserId, false);

                GroupQuestionCls[] GroupQuestions = GroupQuestionBll.ReadingGroupQuestionForAccountType(SiteId, UserType);
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string WebPartLayoutRoot = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);

                string Html =
                   "  <h3>Danh sách các nhóm ngân hàng câu hỏi</h3>\r\n";
                if (GroupQuestions.Length == 0)
                {
                    Html += "<div class=CssNoData>Chưa có nhóm nào</div>\r\n";
                }
                else
                {
                    Html += "<div class=tabcontent>\r\n" +
                            "   <table>\r\n" +
                            "   <tr>\r\n" +
                            "       <th></th>\r\n" +
                            "       <th>Tên chuyên mục</th>\r\n" +
                            "       <th>Mô tả</th>\r\n" +
                            "       <th></th>\r\n" +
                            "       <th></th>\r\n" +
                            "       <th></th>\r\n" +
                            " </tr>\r\n";
                    for (int iIndex = 0; iIndex < GroupQuestions.Length; iIndex++)
                    {
                        bool CheckFunMan = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupQuestionPermission.StaticId, GroupQuestionPermission.funcManage, GroupQuestions[iIndex].GroupQuestionId, WebSessionUtility.GetCurrentLoginUser().UserId, false);
                        bool CheckfuncAccess = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).CheckPermission(SiteId, GroupQuestionPermission.StaticId, GroupQuestionPermission.funcAccess, GroupQuestions[iIndex].GroupQuestionId, WebSessionUtility.GetCurrentLoginUser().UserId, false);

                        if (!CheckfuncAccess) continue;

                        Html +=
                            " <tr>\r\n" +
                            "   <td style=\"width:20px;\"><img title=\"" + GroupQuestions[iIndex].Description + "\" alt=\"" + GroupQuestions[iIndex].Description + "\" src=\"" + WebPartLayoutRoot + "/exam/GroupQuestion.png\" class=image></td>\r\n" +
                            "   <td><a href=\"GroupQuestionTreeView.aspx?RId=" + GroupQuestions[iIndex].GroupQuestionId + "&AccountType=" + UserType + "\">" + GroupQuestions[iIndex].GroupQuestionName + "</a></td>\r\n" +
                            "   <td>" + GroupQuestions[iIndex].Description + "</td>\r\n";                        

                        if (CheckFunMan)
                        {
                            Html +=
                                "   <td class=tdButton><input type=\"button\" class=\"button\" onclick=\"javascript:ClientDelete('" + GroupQuestions[iIndex].GroupQuestionId + "');\" value=\"Xóa\"></td>\r\n" +
                                "   <td class=tdButton><input type=\"button\" class=\"button\" onclick=\"javascript:ClientUpdate('" + GroupQuestions[iIndex].GroupQuestionId + "');\" value=\"Sửa\"></td>\r\n" +
                                "   <td class=tdButton><input type=\"button\" class=\"button\" onclick=\"javascript:window.open('GroupQuestionTreeView.aspx?RId=" + GroupQuestions[iIndex].GroupQuestionId + "&AccountType=" + UserType + "','_self');\" value=\"Quản lý\"></td>\r\n";
                        }
                        else 
                        {
                            Html +=
                                "   <td></td>\r\n" +
                                "   <td></td>\r\n" +
                                "   <td class=tdButton><input type=\"button\" class=\"button\" onclick=\"javascript:window.open('GroupQuestionTreeView.aspx?RId=" + GroupQuestions[iIndex].GroupQuestionId + "&AccountType=" + UserType + "','_self');\" value=\"Quản lý\"></td>\r\n";
                        }
                        Html +=
                            " </tr>\r\n";
                    }
                    Html +=
                        "</table>\r\n" +
                        "</div>\r\n";
                }

                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        //[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        //public static AjaxOut BuildSubTreeView(string SiteId, string ParentAccountType)
        //{
        //    AjaxOut OAjaxOut = new AjaxOut();
        //    try
        //    {
        //        string Html = "";
        //        AccountTypeCls[] AccountTypes = SystemBussinessUtility.CreateSystemsBussinessProcess(SiteId).ReadingAccountType(SiteId, ParentAccountType);
        //        Html +=
        //            "<ul>\r\n";
        //        for (int iIndex = 0; iIndex < AccountTypes.Length; iIndex++)
        //        {
        //            Html +=
        //                    "<li class=\"folder expanded\"><a target=\"_self\" href=\"" + AccountTypes[iIndex].AccountType + "\">" + AccountTypes[iIndex].Description + "</a>\r\n" +
        //                        BuildSubTreeView(SiteId, AccountTypes[iIndex].AccountType).HtmlContent +
        //                    "</li>\r\n";
        //        }

        //        Html += "</ul>\r\n";
        //        OAjaxOut.HtmlContent = Html;
        //    }
        //    catch (Exception ex)
        //    {
        //        OAjaxOut.Error = true;
        //        OAjaxOut.InfoMessage = ex.Message.ToString();
        //        OAjaxOut.HtmlContent = ex.Message.ToString();
        //    }
        //    return OAjaxOut;
        //}


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideDeleteGroupQuestion(
            string SiteId,
            string GroupQuestionId,
            string UserType)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                GroupQuestionBll.DeleteGroupQuestion(SiteId, GroupQuestionId);
                OAjaxOut.HtmlContent = ServerSideReading(SiteId, UserType).HtmlContent;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }



        public static string GetPlugInAddGroupQuestionJavascript(string SiteId, bool UserAjax)
        {
            string RetHtml =
                    "<script language=javascript>\r\n" +
                    "   function SaveAddGroupQuestion()\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       RootGroupQuestionId=document.getElementById('txtRootGroupQuestionId').value;\r\n" +
                    "       ParentGroupQuestionId=document.getElementById('txtParentGroupQuestionId').value;\r\n" +
                    "       GroupQuestionName = document.getElementById('txtGroupQuestionName').value;\r\n" +
                    "       GroupQuestionDescription = document.getElementById('txtGroupQuestionDescription').value;\r\n" +
                    "       SortIndex= document.getElementById('txtSortIndex').value;\r\n" +
                    "       AccountType= document.getElementById('txtAccountType').value;\r\n" +
                    "       OAjaxOut=Portal.Exam.Render.GroupQuestionRenderBll.ServerSideAddGroupQuestion(SiteId,AccountType, GroupQuestionName,GroupQuestionDescription, RootGroupQuestionId, ParentGroupQuestionId, SortIndex).value;\r\n" +
                    "       if(OAjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(OAjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n";
            if (UserAjax)
            {
                RetHtml +=
                    "       AddTreeNode(OAjaxOut.RefKeyId,GroupQuestionName);\r\n";
            }
            RetHtml +=
                    "       document.getElementById('txtGroupQuestionName').value='';\r\n" +
                    "       document.getElementById('txtGroupQuestionDescription').value='';\r\n" +
                    "       document.getElementById('txtSortIndex').value=parseInt(SortIndex)+1;\r\n" +
                    "       document.getElementById('txtGroupQuestionName').focus();\r\n" +
                    "   }\r\n" +
                    "</script>\r\n";
            return RetHtml;
        }

        public static string GetPlugInUpdateGroupQuestionJavascript(string SiteId, bool UserAjax)
        {
            string RetHtml =
                    "<script language=javascript>\r\n" +
                    "   function SaveUpdateGroupQuestion(GroupQuestionId)\r\n" +
                    "   {\r\n" +
                    "       SiteId='" + SiteId + "';\r\n" +
                    "       GroupQuestionName = document.getElementById('txtGroupQuestionName').value;\r\n" +
                    "       GroupQuestionDescription = document.getElementById('txtGroupQuestionDescription').value;\r\n" +
                    "       SortIndex= document.getElementById('txtSortIndex').value;\r\n" +
                    "       OAjaxOut=Portal.Exam.Render.GroupQuestionRenderBll.ServerSideUpdateGroupQuestion(SiteId,GroupQuestionId, GroupQuestionName,GroupQuestionDescription, SortIndex).value;\r\n" +
                    "       if(OAjaxOut.Error)\r\n" +
                    "       {\r\n" +
                    "           alert(OAjaxOut.InfoMessage);\r\n" +
                    "           return;\r\n" +
                    "       }\r\n";
            if (UserAjax)
            {
                RetHtml +=
                    "       SaveTreeNode(GroupQuestionId,GroupQuestionName);\r\n" +
                    "       BackFromUpdateGroupQuestion();\r\n";
            }
            else
            {
                RetHtml +=
                    "   window.open('GroupQuestion.aspx','_self');\r\n";
            }
            RetHtml +=
                    "   }\r\n" +
                    "</script>\r\n";
            return RetHtml;
        }



        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawAddGroupQuestion(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            string ParentGroupQuestionId = (string)WebEnvironments.Request(SiteId, "ParentGroupQuestionId");
            if (string.IsNullOrEmpty(ParentGroupQuestionId)) ParentGroupQuestionId = "";

            string RootGroupQuestionId = (string)WebEnvironments.Request(SiteId, "RootGroupQuestionId");
            if (string.IsNullOrEmpty(RootGroupQuestionId)) RootGroupQuestionId = "";

            string AccountType = (string)WebEnvironments.Request(SiteId, "AccountType");
            string BackUrl = "GroupQuestion.aspx";

            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string WebPartLayoutRoot = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);

                string Html =
                    GetPlugInAddGroupQuestionJavascript(SiteId, false) +
                    "<input type=hidden id=txtAccountType value=\"" + AccountType + "\">\r\n" +
                    "<input type=hidden id=txtRootGroupQuestionId value=\"" + RootGroupQuestionId + "\">\r\n" +
                    "<input type=hidden id=txtParentGroupQuestionId value=\"" + ParentGroupQuestionId + "\">\r\n" +
                    "<div class=FormFunction id=divListForm>\r\n" +
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:SaveAddGroupQuestion();\"><img class=image src=\"" + IconRoot + "/Save.png\"><div>Ghi lại</div></li>\r\n" +
                   "            <li onclick=\"javascript:window.open('" + BackUrl + "','_self');\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "</div>\r\n" +
                    "<div class=CssTip>Cho phép người quản lý tạo ra các nhóm ngân hàng câu hỏi. Các nhóm này sẽ chứa các câu hỏi trong hệ thống ngân hàng</div>\r\n" +
                    "<div class=CssFormSaveUpdate>\r\n" +
                    "   <table>\r\n" +
                    "       <tr>\r\n" +
                    "           <td  style=\"width:100px;\"><img style=\"width:100px;margin-right:10px;\" src=\"" + WebPartLayoutRoot + "/Exam/GroupQuestion.png\"></td>\r\n" +
                    "           <td>\r\n" +
                    "   <table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Tên nhóm:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtGroupQuestionName></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Mô tả:</td>\r\n" +
                    "       <td class=Col2><textarea id=txtGroupQuestionDescription type=textarea class=textarea></textarea></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Thứ tự:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtSortIndex value=\"0\"></td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "</td>\r\n" +
                    "</tr>\r\n" +
                    "</table>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawAddGroupQuestionForAjax(
            string SiteId,
            string RootGroupQuestionId,
            string ParentGroupQuestionId,            
            string AccountType,
            string BackScript 
            )
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string WebPartLayoutRoot = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);

                string Html =
                    "<input type=hidden id=txtAccountType value=\"" + AccountType + "\">\r\n" +
                    "<input type=hidden id=txtRootGroupQuestionId value=\"" + RootGroupQuestionId + "\">\r\n" +
                    "<input type=hidden id=txtParentGroupQuestionId value=\"" + ParentGroupQuestionId + "\">\r\n" +
                    "<div class=FormFunction id=divListForm>\r\n" +
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:SaveAddGroupQuestion();\"><img class=image src=\"" + IconRoot + "/Save.png\"><div>Ghi lại</div></li>\r\n" +
                   "            <li onclick=\"" + BackScript + "\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "</div>\r\n" +
                    "<div class=CssTip>Cho phép người quản lý tạo ra các nhóm ngân hàng câu hỏi. Các nhóm này sẽ chứa các câu hỏi trong hệ thống ngân hàng</div>\r\n" +
                    "<div class=CssFormSaveUpdate>\r\n" +
                    "   <table>\r\n" +
                    "       <tr>\r\n" +
                    "           <td  style=\"width:100px;\"><img style=\"width:100px;margin-right:10px;\" src=\"" + WebPartLayoutRoot + "/exam/GroupQuestion.png\"></td>\r\n" +
                    "           <td>\r\n" +
                    "   <table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Tên nhóm:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtGroupQuestionName></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Mô tả:</td>\r\n" +
                    "       <td class=Col2><textarea id=txtGroupQuestionDescription type=textarea class=textarea></textarea></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Thứ tự:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtSortIndex value=\"0\"></td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "</td>\r\n" +
                    "</tr>\r\n" +
                    "</table>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }


        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideAddGroupQuestion(
            string SiteId,
            string AccountType,
            string GroupQuestionName,
            string Description,
            string RootGroupQuestionId,
            string ParentGroupQuestionId,
            string SortIndex)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                if (string.IsNullOrEmpty(GroupQuestionName)) throw new Exception("Chưa nhập tên nhóm!");
                OAjaxOut.RefKeyId = GroupQuestionBll.AddGroupQuestion(SiteId, AccountType, GroupQuestionName, Description, RootGroupQuestionId, ParentGroupQuestionId, SortIndex);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut ServerSideUpdateGroupQuestion(
            string SiteId,
            string GroupQuestionId,
            string GroupQuestionName,
            string Description,
            string SortIndex)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                GroupQuestionBll.SaveGroupQuestion(SiteId, GroupQuestionId, GroupQuestionName, Description, SortIndex);
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawUpdateGroupQuestionForAjax(string SiteId, string GroupQuestionId, string BackScript)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string WebPartLayoutRoot = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);


                GroupQuestionCls OGroupQuestion = GroupQuestionBll.CreateGroupQuestionModel(SiteId, GroupQuestionId);
                string Html =
                    "<div class=FormFunction id=divListForm>\r\n" +
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:SaveUpdateGroupQuestion('" + GroupQuestionId + "');\"><img class=image src=\"" + IconRoot + "/Save.png\"><div>Ghi lại</div></li>\r\n" +
                   "            <li onclick=\"" + BackScript + "\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "</div>\r\n" +
                    "<div class=CssTip>Cho phép người quản lý sửa nhóm ngân hàng câu hỏi. Các nhóm này sẽ chứa các câu hỏi trong hệ thống ngân hàng</div>\r\n" +
                    "<div class=CssFormSaveUpdate>\r\n" +
                    "   <table>\r\n" +
                    "       <tr>\r\n" +
                    "           <td  style=\"width:100px;\"><img style=\"width:100px;margin-right:10px;\" src=\"" + WebPartLayoutRoot + "/Exam/GroupQuestion.png\"></td>\r\n" +
                    "           <td>\r\n" +
                    "   <table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Tên nhóm:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtGroupQuestionName value=\"" + OGroupQuestion.GroupQuestionName + "\"></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Mô tả:</td>\r\n" +
                    "       <td class=Col2><textarea id=txtGroupQuestionDescription type=textarea class=textarea>" + OGroupQuestion.Description + "</textarea></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Thứ tự:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtSortIndex value=\"" + OGroupQuestion.SortIndex + "\"></td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "</td>\r\n" +
                    "</tr>\r\n" +
                    "</table>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

        [AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
        public static AjaxOut DrawUpdateGroupQuestion(string SiteId)
        {
            AjaxOut OAjaxOut = new AjaxOut();
            try
            {
                SiteParam OSiteParam = WebEnvironments.CreateSiteParam(SiteId);
                string GroupQuestionId = (string)WebEnvironments.Request(SiteId, "GroupQuestionId");
                string IconRoot = WebConfig.GetButtonIconRoot(OSiteParam);
                string WebPartLayoutRoot = WebConfig.GetWebPartLayoutIconRoot(OSiteParam);


                GroupQuestionCls OGroupQuestion = GroupQuestionBll.CreateGroupQuestionModel(SiteId, GroupQuestionId);
                string Html =
                    GetPlugInUpdateGroupQuestionJavascript(SiteId, false) +
                    "<div class=FormFunction id=divListForm>\r\n" +
                   " <div class=DatabaseFunction>\r\n" +
                   "        <ul>\r\n" +
                   "            <li onclick=\"javascript:SaveUpdateGroupQuestion('" + GroupQuestionId + "');\"><img class=image src=\"" + IconRoot + "/Save.png\"><div>Ghi lại</div></li>\r\n" +
                   "            <li onclick=\"window.open('GroupQuestion.aspx','_self');\"><img class=image src=\"" + IconRoot + "/back.png\"><div>Quay lại</div></li>\r\n" +
                   "        </ul>\r\n" +
                   "  </div>\r\n" +
                   "</div>\r\n" +
                    "<div class=CssTip>Cho phép người quản lý sửa nhóm ngân hàng câu hỏi. Các nhóm này sẽ chứa các câu hỏi trong hệ thống ngân hàng</div>\r\n" +
                    "<div class=CssFormSaveUpdate>\r\n" +
                    "   <table>\r\n" +
                    "       <tr>\r\n" +
                    "           <td  style=\"width:100px;\"><img style=\"width:100px;margin-right:10px;\" src=\"" + WebPartLayoutRoot + "/Exam/GroupQuestion.png\"></td>\r\n" +
                    "           <td>\r\n" +
                    "   <table>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Tên nhóm:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtGroupQuestionName value=\"" + OGroupQuestion.GroupQuestionName + "\"></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Mô tả:</td>\r\n" +
                    "       <td class=Col2><textarea id=txtGroupQuestionDescription type=textarea class=textarea>" + OGroupQuestion.Description + "</textarea></td>\r\n" +
                    "   </tr>\r\n" +
                    "   <tr>\r\n" +
                    "       <td class=Col1>Thứ tự:</td>\r\n" +
                    "       <td class=Col2><input class=textbox type=textbox id=txtSortIndex value=\"" + OGroupQuestion.SortIndex + "\"></td>\r\n" +
                    "   </tr>\r\n" +
                    "</table>\r\n" +
                    "</td>\r\n" +
                    "</tr>\r\n" +
                    "</table>\r\n" +
                    "</div>\r\n";
                OAjaxOut.HtmlContent = Html;
            }
            catch (Exception ex)
            {
                OAjaxOut.Error = true;
                OAjaxOut.InfoMessage = ex.Message.ToString();
                OAjaxOut.HtmlContent = ex.Message.ToString();
            }
            return OAjaxOut;
        }

    }
}
